﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Cosmetic.DataEntity;

namespace Cosmetic.Logic
{
    public class PlateManager : LogicBase
    {

        public List<Product> GetPlateCosmeticProducts()
        {
            var result = from thePlate in m_CosmeticDC.PlateJapaneseCosmetics
                         join theProduct in m_CosmeticDC.Products
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result.ToList();
        }

        public IEnumerable GetPlateCosmeticProducts2()
        {
            var result = from thePlate in m_CosmeticDC.PlateJapaneseCosmetics
                         join theProduct in m_CosmeticDC.Products
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select new
                         {
                             Id = thePlate.Id,
                             Sequence = thePlate.Sequence,
                             name = theProduct.Name
                         };
            return result;
        }

        public void DeletePlateCosmeticProtudct(PlateJapaneseCosmetic aUser)
        {
            m_CosmeticDC.PlateJapaneseCosmetics.DeleteOnSubmit(aUser);
            m_CosmeticDC.SubmitChanges();
        }

        public PlateJapaneseCosmetic GetPlateJapaneseCosmetic(int id)
        {
            return m_CosmeticDC.PlateJapaneseCosmetics.Single(theProect => theProect.Id == id);
        }

        public IEnumerable GetjiujuProducts()
        {
            var result = from thePlate in m_CosmeticDC.jiuju
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result;
        }

        public IEnumerable GetPlateCloth()
        {
            var result = from thePlate in m_CosmeticDC.PlateExcellentCloths
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result.Take(5);
        }

        public IEnumerable GetPlateHouseHold()
        {
            var result = from thePlate in m_CosmeticDC.PlateHouseHolds
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result;
        }
        public IEnumerable Getwubaiproduct()
        {
            var result = from thePlate in m_CosmeticDC.wubai
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result;
        }
        public IEnumerable Getyiqianproduct()
        {
            var result = from thePlate in m_CosmeticDC.yiqian
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result;
        }
        public IEnumerable Getsanqianproduct()
        {
            var result = from thePlate in m_CosmeticDC.sanqian
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result;
        }
        public IEnumerable Getyiwanproduct()
        {
            var result = from thePlate in m_CosmeticDC.yiwan
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result.Take(5);
        }


        /*热门推荐 */
        public IEnumerable Gethotpro()
        {
            var result = from thePlate in m_CosmeticDC.MonthlySales
                         join theProduct in m_CosmeticDC.Products
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result.Take(4);
        }

        public IEnumerable Gethotpro1()
        {
            var result = from thePlate in m_CosmeticDC.MonthlySales
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result.Take(1);

        }

        public IEnumerable Gethotpro2()
        {
            var result = from thePlate in m_CosmeticDC.MonthlySales
                         join theProduct in m_CosmeticDC.Products
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select new
                         {

                             Id = thePlate.Id,
                             Sequence = thePlate.Sequence,
                             name = theProduct.Name
                         };
            return result;
        }
        public WeeklySales getxinpin(int id)
        {
            return m_CosmeticDC.WeeklySales.Single(theProect => theProect.Id == id);
        }


        public MonthlySales getmonth(int id)
        {
            return m_CosmeticDC.MonthlySales.Single(theProect => theProect.Id == id);
        }
        /* 新品上市  */

        public IEnumerable Getxinpinpro()
        {
            var result = from thePlate in m_CosmeticDC.WeeklySales
                         join theProduct in m_CosmeticDC.Products
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result.Take(3);
        }

        public void Deleteweek(WeeklySales aUser)
        {
            m_CosmeticDC.WeeklySales.DeleteOnSubmit(aUser);
            m_CosmeticDC.SubmitChanges();
        }

        public void Deletemonth(MonthlySales aUser)
        {
            m_CosmeticDC.MonthlySales.DeleteOnSubmit(aUser);
            m_CosmeticDC.SubmitChanges();
        }
        public IEnumerable Getxinpinpro2()
        {
            var result = from thePlate in m_CosmeticDC.WeeklySales
                         join theProduct in m_CosmeticDC.Products
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select new
                         {

                             Id = thePlate.Id,
                             Sequence = thePlate.Sequence,
                             name = theProduct.Name
                         };
            return result;
        }

        /* 新品上市*/

        public void Insertxinpin(WeeklySales aProduct)
        {
            m_CosmeticDC.WeeklySales.InsertOnSubmit(aProduct);
            m_CosmeticDC.SubmitChanges();
        }
        /* 热门推荐 */

        public void Inserthot(MonthlySales aProduct)
        {
            m_CosmeticDC.MonthlySales.InsertOnSubmit(aProduct);
            m_CosmeticDC.SubmitChanges();
        }


        /* 商城推荐 */

        public void InsertPlateCosmeticProduct(PlateJapaneseCosmetic aProduct)
        {
            m_CosmeticDC.PlateJapaneseCosmetics.InsertOnSubmit(aProduct);
            m_CosmeticDC.SubmitChanges();
        }


        public IEnumerable Getxinpinpro1()
        {
            var result = from thePlate in m_CosmeticDC.WeeklySales
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.ProductId equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result.Take(1);
        }
        /*首页下面滚动的产品  */

        public IEnumerable Getfontprod()
        {
            var result = from thePlate in m_CosmeticDC.fontprod
                         join theProduct in m_CosmeticDC.ProductInfos
                         on thePlate.productid equals theProduct.ProductId
                         orderby thePlate.Sequence
                         select theProduct;
            return result;
        }

        public IEnumerable GetTimeLimitSales()
        {
            var result = from theLimitSale in m_CosmeticDC.TimeLimitedSales
                         join theProduct in m_CosmeticDC.ProductInfos
                         on theLimitSale.ProductId equals theProduct.ProductId
                         orderby theLimitSale.Sequence
                         select new
                         {
                             Id = theLimitSale.Id,
                             ProductId = theProduct.ProductId,
                             PictureUrl = theProduct.PictureUrl,
                             ProductPrice = theProduct.网络零售价,
                             Discount = theLimitSale.Discount,
                             Name = theProduct.Name,
                             EndTime = theLimitSale.EndTime
                         };
            return result.Take(2);
        }
        public IEnumerable GetAllTimeLimitSales()
        {
            var result = from theLimitSale in m_CosmeticDC.TimeLimitedSales
                         join theProduct in m_CosmeticDC.ProductInfos
                         on theLimitSale.ProductId equals theProduct.ProductId
                         orderby theLimitSale.Sequence
                         select new
                         {
                             Id = theLimitSale.Id,
                             ProductId = theProduct.ProductId,
                             PictureUrl = theProduct.PictureUrl,
                             ProductPrice = theProduct.网络零售价,
                             Discount = theLimitSale.Discount,
                             Name = theProduct.Name,
                             EndTime = theLimitSale.EndTime,
                             ProductCode = theProduct.ProductCode
                         };
            return result;
        }
        public void InsertTimeLimitSales(string productId, DateTime endtime, decimal discount)
        {
            TimeLimitedSale maxSequenceTimeLimitSale = (from time in m_CosmeticDC.TimeLimitedSales
                                                        orderby time.Sequence descending
                                                        select time).Take(1).Single();

            TimeLimitedSale tls = new TimeLimitedSale();
            tls.Discount = discount;
            tls.EndTime = endtime;
            tls.Sequence = maxSequenceTimeLimitSale.Sequence + 1;
            tls.ProductId = new Guid(productId);
            tls.CreateTime = DateTime.Now;

            m_CosmeticDC.TimeLimitedSales.InsertOnSubmit(tls);
            m_CosmeticDC.SubmitChanges();
        }

        public void DeleteTimeLimitSales(string Id)
        {
            TimeLimitedSale tls = (from tt in m_CosmeticDC.TimeLimitedSales
                                   where tt.Id.ToString() == Id
                                   select tt).Single();
            m_CosmeticDC.TimeLimitedSales.DeleteOnSubmit(tls);
            m_CosmeticDC.SubmitChanges();
        }

    }
}
